import { ref } from "vue";
import { defineStore } from "pinia";

const useUserStore = defineStore("user", () => {
  const token = ref(sessionStorage.getItem("token") || "");
  const userInfo = ref(sessionStorage.getItem("userInfo") || null);
  const jwt = ref(sessionStorage.getItem("jwt") || "");

  const setToken = (value) => {
    token.value = value;
  };
  const setJwt = (value) => {
    jwt.value = value;
  };
  const setUserInfo = (value) => {
    userInfo.value = value;
    sessionStorage.setItem("userInfo", JSON.stringify(value));
  };

  return {
    token,
    jwt,
    userInfo,
    setToken,
    setJwt,
    setUserInfo,
  };
});

export default useUserStore;
